package com.java.s5;

public class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name) {
        this();
        this.name=name;
    }

    public Person(String name, int age) {
        this(name);
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age>0){
            this.age = age;
        }
       this.age=0;
    }
    //判断两个对象是否相等
    public boolean compareTo(Person per){
        if(per==null){
            return false;
        }
        if (this==per){ //地址相同
            return true;
        }
        if (this.name.equals(per.name)
                &&this.age== per.age)
        {
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return
                "姓名：'" + this.name +
                ", 年龄：" + this.age
                ;
    }
}
